const fs = require('fs');
const path = require('path');
const dir = '../design-ui/icons';
async function main(){
    const fullDir = path.resolve(__dirname, dir);
    const files = fs.readdirSync(fullDir);
    for(const file of files){
        const filePath = path.resolve(fullDir, file);
        let fileContent = fs.readFileSync(filePath, 'utf-8');
        const iconName = (file.split('.')[0])
            .replace(/^[a-z]/, match => match.toUpperCase())
            .replace(/_[a-z]/g, match => match.toUpperCase().slice(1));
        const iconPath = path.resolve(fullDir, `NdIcon${iconName}.vue`);
        let iconContent = '<template>\n';
        fileContent = fileContent.replace(/fill=".*?"/g, 'fill="currentColor"');
        // 需要添加class="nd-icon"
        fileContent = fileContent.replace(/<svg (.*?)>(.*)<\/svg>/, '<svg class="nd-icon" $1>$2</svg>');
        iconContent += '    ' + fileContent + '\n';
        iconContent += '</template>';
        fs.writeFileSync(iconPath, iconContent);
    }
}
main();